
/*    HTTP Host:  static.ak.fbcdn.net                                          */
/*    Generated:  July 5th 2009 7:54:49 PM PDT                                 */
/*      Machine:  10.16.139.104                                                */
/*       Source:  Backing Store                                                */
/*     Location:  js/s71agrnn1iosks4o.pkg.js h:6v87mudz                        */
/*       Locale:  en_US                                                        */
/*         Path:  js/s71agrnn1iosks4o.pkg.js                                   */
function pymkGrid(grid_id, show_explanation) {
	copy_properties(this, {used_ids:[], boxes_displayed:0, payload_timeouts:0, grid_id:null, pymk_more_link:null, show_explanation:null});
	if (grid_id && ge(grid_id)) {
		this.show_explanation = !!show_explanation;
		this.grid_obj = $(grid_id);
		var id_divs = DOM.scry(this.grid_obj, "div.friend_grid_col");
		for (var i = 0; i < id_divs.length; i++) {
			this.used_ids.push(parseInt(id_divs[i].getAttribute("id").substring(3)));
			this.boxes_displayed++;
		}
		var more_link = DOM.scry(this.grid_obj, "a.show_more");
		if (more_link) {
			this.pymk_more_link = more_link[0];
		}
	} else {
		Util.error("pymkGrid: Either the grid you have specified is invalid or is not detectable in the DOM.");
	}
}
copy_properties(pymkGrid.prototype, {addFriend:function (uid, page, score, source, log) {
	this.modifyFriendship(uid, "add", null, page, score, source, log);
	return;
}, hideFriend:function (uid, page, score, source) {
	this.modifyFriendship(uid, "blacklist", null, page, score, source);
	return;
}, modifyFriendship:function (uid, action_type, home_panel, page, score, source, log) {
	var friend_data = this.getGridData($("fg_" + uid));
	var asyncData = {used:this.used_ids, replace:uid, get:1, explanation:this.show_explanation, page:page};
	if (action_type == "blacklist") {
		asyncData.click_type = "hide";
		asyncData.blacklist_type = "blacklist";
		asyncData.score = score;
		asyncData.source = source;
	} else {
		if (log) {
			asyncData.click_type = "add";
			asyncData.score = score;
			asyncData.source = source;
		}
	}
	new AsyncRequest().setURI("/ajax/friend_guess.php").setData(asyncData).setHandler(bind(this, this.asyncHandleModify)).setReplayable(false).send();
	var friend_box = $("fg_" + uid);
	animation(friend_box).from("opacity", 1).to("opacity", 0).duration(300).go();
	if (home_panel) {
		home_panel.addTo("outgoing", home_panel.constructGridItem(friend_data));
	}
	return;
}, asyncHandleRefresh:function (async) {
	payload = async.getPayload();
	if (payload.victim && payload.victim.length > 0) {
		for (var i = 0; i < payload.victim.length; i++) {
			if (this.used_ids[i]) {
				animation($("fg_" + this.used_ids[i])).from("opacity", 1).to("opacity", 0).duration(300).go();
			}
		}
		for (var i = 0; i < payload.victim.length; i++) {
			if (this.used_ids[i]) {
				this.replaceItem(this.used_ids[i], payload.victim[i]);
			}
		}
		for (var i = 0; i < payload.victim.length; i++) {
			this.used_ids.unshift(payload.victim[i].uid);
		}
	}
	if (!payload.more) {
		this._hideMoreLink();
	}
}, asyncHandleModify:function (async) {
	payload = async.getPayload();
	if (payload.victim && payload.victim.length > 0) {
		this.replaceItem(payload.replace, payload.victim[0]);
	} else {
		this.hideItem(payload.replace);
	}
	return;
}, replaceItem:function (replace, victim) {
	var replace_id = "fg_" + replace;
	var box_id = "fg_" + victim.uid;
	if (!ge(box_id)) {
		var new_box = DOM.create("div", {id:box_id, className:"friend_grid_col clearfix"}, HTML(victim.box_content));
		DOM.replace($(replace_id), new_box);
		animation($(box_id)).from("opacity", 0).to("opacity", 1).duration(400).go();
		this.used_ids.push(victim.uid);
	} else {
		this.hideItem(replace);
	}
}, hideItem:function (replace) {
	this.payload_timeouts++;
	var replace_id = "fg_" + replace;
	var anim = null;
	var suggestions = $$("#home_sidebar .sidebar_item.pymk");
	if (1 == suggestions.length && 1 == $$("#pymk_ajax_grid .friend_grid_row").length) {
		anim = animation(suggestions[0]);
	} else {
		hide("fg_add_" + replace);
		$(replace_id).unreplaceable = true;
		var pymkRow = $(replace_id).parentNode;
		var collapseRow = true;
		for (var i = 0; i < pymkRow.childNodes.length; i++) {
			if (!pymkRow.childNodes[i].unreplaceable) {
				collapseRow = false;
				break;
			}
		}
		if (collapseRow) {
			anim = animation(pymkRow).ondone(DOM.remove.bind(null, pymkRow));
		}
	}
	if (anim) {
		anim.to("height", 0).duration(550).hide().ease(animation.ease.end).go();
	}
	this._hideMoreLink();
}, constructGridItem:function (grid_data) {
	return this.constructRawGridItem(grid_data.uid, grid_data.content);
}, constructRawGridItem:function (uid, item_content) {
	var gridItem = document.createElement("div");
	CSS.addClass(gridItem, "friend_grid_col");
	gridItem.setAttribute("id", "friend_" + uid);
	gridItem.innerHTML = item_content;
	return gridItem;
}, getGridData:function (grid_object) {
	if (CSS.hasClass(grid_object, "friend_grid_col")) {
		var gridData = {content:grid_object.innerHTML, uid:grid_object.getAttribute("id").toString().slice(3)};
		return gridData;
	}
}, _removeID:function (uid) {
	for (var i = 0; i < this.used_ids.length; i++) {
		if (this.used_ids[i] == uid) {
			this.used_ids.splice(i, 1);
		}
	}
	return;
}, _hideMoreLink:function () {
	if (this.pymk_more_link) {
		this.pymk_more_link.style.visibility = "hidden";
		this.pymk_more_link = null;
	}
}});
function pymk_friend_added(link_object) {
	pymk_add_friend(link_object.uid, link_object.render_explanation, null, link_object.page);
}
function pymk_friend_added_no_ajax(link_object) {
	var link = $("fg_add_" + link_object.uid);
	var newNode = $N("span", {className:"holder inactive"}, _tx("Friend Requested"));
	DOM.replace(link, newNode);
	var asyncData = {uid:link_object.uid, page:link_object.page, click_type:"add", score:link_object.score, source:link_object.source};
	new AsyncSignal("/ajax/pymk_logging.php", asyncData).send();
}
function pymk_page_added(uid, has_explanation, page, score, source, log) {
	pymk_add_friend(uid, has_explanation, null, page, score, source, log);
}
function pymk_add_friend(uid, has_explanation, existingGrid, page, score, source, log) {
	if (!existingGrid) {
		existingGrid = new pymkGrid("pymk_ajax_grid", has_explanation || false);
	}
	existingGrid.addFriend(uid, page, score, source, log);
}
function pymk_hide_friend(uid, has_explanation, existingGrid, page, score, source) {
	if (!existingGrid) {
		existingGrid = new pymkGrid("pymk_ajax_grid", has_explanation);
	}
	if (!score) {
		score = -1;
	}
	if (!source) {
		source = "u";
	}
	existingGrid.hideFriend(uid, page, score, source);
}
function pymk_log_profile_click(uid, page, score, source) {
	var asyncData = {click_type:"profile", replace:uid, page:page, score:score, source:source};
	new AsyncRequest().setURI("/ajax/friend_guess.php").setData(asyncData).setReplayable(false).send();
}
function VideoHistogram() {
	this.videos = {};
	this.video_payloads = {};
	this.listening = false;
	this.checking = false;
}
VideoHistogram.prototype.start = function (swf_id) {
	var new_video = document[swf_id] || window[swf_id];
	this.videos[swf_id] = new_video;
	this.listening = true;
};
VideoHistogram.prototype.videoFinished = function (swf_id, payload) {
	this.videos[swf_id] = null;
	this.setPayload(swf_id, payload);
	this.updateServer();
};
VideoHistogram.prototype.setPayload = function (swf_id, payload) {
	this.video_payloads[swf_id] = payload;
};
VideoHistogram.prototype.updateServer = function () {
	var big_payload = [];
	for (var swf_id in this.video_payloads) {
		var video_report = this.video_payloads[swf_id];
		this.video_payloads[swf_id] = null;
		if (video_report) {
			big_payload.push(video_report);
		}
	}
	var json_payload = JSON.encode(big_payload);
	new AsyncSignal("/video/motion_log.php", {"h":json_payload}).send();
	this.listening = false;
	this.checking = false;
};
VideoHistogram.prototype.checkStatus = function () {
	if (this.listening) {
		this.checking = true;
		for (var v in this.videos) {
			if (this.videos[v].reportTime) {
				this.videos[v].reportTime();
			}
		}
		this.updateServer();
	}
};
if (window.Bootloader) {
	Bootloader.done(["js/s71agrnn1iosks4o.pkg.js"]);
}

